﻿@using TBM.Models
@{
    Layout = null;
    Group GInfo = ViewBag.Group as Group;
	List<TBM.Models.MainMenu> MenuList = (List<TBM.Models.MainMenu>)ViewBag.MainMenu;
}
@helper TreeNodes(TBM.Models.MainMenu parent, bool IsAdminGroup){
	if(parent.SubMenu != null && parent.SubMenu.Any()){
		foreach(TBM.Models.MainMenu item in parent.SubMenu){
			<div class="pl-50 mt-5">
				<label class="checkbox-inline align-left">
					@if(item.IsChecked || IsAdminGroup){
						<input type="checkbox" name="id" value="@item.ID" checked="checked" @(IsAdminGroup ? "disabled=\"disabled\"" : "")> 
					}else{
						<input type="checkbox" name="id" value="@item.ID"> 
					}
					@item.PageName
				</label>
				@TreeNodes(item, IsAdminGroup)
			</div>
		}
	}
}

<div class="header-caption">
    分组信息
</div>  
<div class="profile-container">
  <div class="row">
    <div class="col-md-12">
        <div class="portlet light">
            <div class="portlet-title tabbable-line">
            <div class="caption caption-md">
                <span class="caption-subject font-blue-madison bold">详细信息 (GID: @GInfo.GID)</span>
            </div>
            <ul class="nav nav-tabs">
                <li class="active">
                <a href="#tab_info" data-toggle="tab">分组信息</a>
                </li>
                <li>
                <a href="#tab_memberlist" data-toggle="tab">成员列表</a>
                </li>
                <li>
                <a href="#tab_permission" data-toggle="tab">权限设置</a>
                </li>
                <li>
                <a href="#tab_menu" data-toggle="tab">菜单配置</a>
                </li>
            </ul>
            </div>
            <div class="portlet-body">
            <div class="tab-content">
                <!-- PERSONAL INFO TAB -->
                <div class="tab-pane active" id="tab_info">
                <form id="updateForm" role="form" action="~/User/UpdateGrouop">
                    <input type="hidden" name="gid" value="@GInfo.GID" />
                    <div class="form-body">
                    <div class="form-group">
                        <label class="control-label">名称</label>
                        <span></span>
                        <input name="groupname" type="text" placeholder="名称" class="form-control" value="@GInfo.GroupName" />
                    </div>
                    <div class="form-group">
                        <label class="control-label">描述</label>
                        <span></span>
                        <textarea name="descr" class="form-control" rows="3" placeholder="关于组的描述">@GInfo.Descr</textarea>
                    </div>
                    <div class="margiv-top-10">
                        <button id="btnUpdateGroup" type="button" class="btn green-haze">更新</button>
                        <button id="btnUpdateGroupCancel" type="button" class="btn default">取消</button>
                    </div>
                    </div>
                </form>
                </div>
                <!-- END PERSONAL INFO TAB -->
                <!-- CHANGE MEMBERSHIHP TAB -->
                <div class="tab-pane" id="tab_memberlist">
                <form id="changeMemberForm" action="~/User/ChangeMember">
                    <input type="hidden" name="gid" value="@GInfo.GID" />
                    <div class="form-group">
                    <div class="alert alert-success">成员列表 （右侧为已加入分组成员，左侧为未加入分组成员）</div>
                    <span></span>
                    <select multiple="multiple" class="multi-select" id="ddlMemberList" name="uids">
                    @foreach(UserListItem item in ViewBag.Users){
                        <option value="@item.UID" @(item.Checked ? "selected=\"selected\"" : "") title="@("uid:" + item.UID)">@item.FullName</option>
                    }
                    </select>
                    </div>
                    <div class="margin-top-10">
                    <button id="btnChangeMember" type="button" class="btn green-haze">更新</button>
                    <button id="btnCancelChange" type="button" class="btn default">取消</button>
                    </div>
                </form>
                </div>
                <!-- END CHANGE MEMBERSHIHP TAB -->
                <!-- PRIVACY SETTINGS TAB -->
                <div class="tab-pane" id="tab_permission">
					<form id="updatePermissionForm" action="~/User/UpdateGroupPermission">
						<input type="hidden" name="gid" value="@GInfo.GID" />
						<table class="table table-light">
							<tbody>
								@foreach(var Parent in ViewBag.ModuleList){
								<tr>
								<td>
									<div class="checkbox-list mb-10">
									<label class="checkbox-inline align-left">
										<input name="moduleid" type="checkbox" value="@Parent.Key.ID" 
										@(GInfo.GID == "_admin" ? "disabled=\"disabled\"" : "")
										@(Parent.Key.IsChecked ? "checked=\"checked=\"" : "")/><b> @("[" + Parent.Key.ControllerDescr + "] " + Parent.Key.ActionDescr) </b>
									</label>
									</div>
									<div class="checkbox-list pl-50">
									@foreach(TBM.Models.Module item in Parent.Value){
									<label class="checkbox-inline align-left">
										<input name="moduleid" type="checkbox" value="@item.ID" 
										@(GInfo.GID == "_admin" ? "disabled=\"disabled\"" : "")
										@(item.IsChecked ? "checked=\"checked=\"" : "")/> @item.ActionDescr
									</label>
									}
									</div>
								</td>
								</tr>
								}
                          
							</tbody>
						</table>
						<!--end profile-settings-->
						@if(GInfo.GID != "_admin"){
						<div class="margin-top-10">
						<button id="btnUpdatePermission" type="button" class="btn green-haze">更新</button>
						<button id="btnCancelUpdatePermission" type="button" class="btn default">取消</button>
						</div>
						}
					</form>
                </div>
                <!-- END PRIVACY SETTINGS TAB -->
                <!-- BEGIN MENU SETTING TAB -->
                <div class="tab-pane" id="tab_menu">
					<form id="updateMenuSettingForm" action="~/User/UpdateGroupMenuPermission">
						<input type="hidden" name="gid" value="@GInfo.GID" />
						<table class="table table-light">
							<tbody>
								@foreach(TBM.Models.MainMenu menuItem in MenuList){
								<tr>
									<td>
										<div class="checkbox-list mb-10">
											<label class="checkbox-inline align-left">
												@if(menuItem.IsChecked || GInfo.GID == "_admin"){
													<input type="checkbox" name="id" value="@menuItem.ID" checked="checked" @(GInfo.GID == "_admin" ? "disabled=\"disabled\"" : "")> 
												}else{
													<input type="checkbox" name="id" value="@menuItem.ID"> 
												}
												@menuItem.PageName
											</label>
											@TreeNodes(menuItem, GInfo.GID == "_admin")
										</div>
									</td>
								</tr>
								}
							</tbody>
						</table>
					</form>
					@if(GInfo.GID != "_admin"){
					<div class="margin-top-10">
						<button id="btnUpdateMenuPermission" type="button" class="btn green-haze">更新</button>
						<button id="btnCancelUpdateMenuPermission" type="button" class="btn default">取消</button>
					</div>
					}
				</div>
                <!-- END MENU SETTING TAB -->
            </div>
            </div>
        </div>      
    </div>
  </div>
</div>
<script type="text/javascript">
    jQuery(document).ready(function () {
        GroupDetail.init();
    });
</script>